package eerbaar.server.gamebuilder.game;

import eerbaar.game.GameFactory;
import eerbaar.game.IGame;
import eerbaar.level.ILevel;
import eerbaar.shared.exceptions.GameException;

public class GameBuilder {

    public IGame build() throws GameException {

        IGame game = GameFactory.createGame();
        ILevel level = new LevelBuilder().build(1);
        if (level == null) {
            throw new GameException("level 1 not found");
        }
        game.setLevel(level);

        return game;
    }

    public IGame nextLevel(IGame game) throws GameException {

        int index = game.getLevel().getComplete().getNext();

        ILevel level = new LevelBuilder().build(index);
        if (level == null) {
            throw new GameException("level " + index + "  not found");
        }

        game.setLevel(level);

        return game;
    }

}
